__all__=(
    "IPFSHelper",
)

import common
from .ipfstools import ipfs_tool


class IPFSHelper:
    __core = ipfs_tool(common.args.IPFSIP,common.args.IPFSPort)
    __core.connection()

    @classmethod
    def upload_file(cls,file_name:str,content:bytes):
        location = cls.__core.uploadincontent(content)
        # location = {"Name":file_name,"Hash":file_hash,"Size":file_size}
        location["Name"] = file_name # 原本的 Name 是随机的
        return location 
        
    @classmethod
    def download_file(cls,file_hash):
        return cls.__core.catfilecontent(file_hash)
    
    @classmethod
    def download_file_with_location(cls,file_location):
        file_hash = file_location["Hash"]
        return cls.download_file(file_hash)
